package com.ruoyi.web.controller.systembasic;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.systembasic.domain.SmesBarcode;
import com.ruoyi.mes.systembasic.service.ISmesBarcodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 条码管理Controller
 *
 * @author simpsense
 * @date 2020-12-14
 */
@RestController
@RequestMapping("/systembasic/barcode")
public class SmesBarcodeController extends BaseController
{
    @Autowired
    private ISmesBarcodeService smesBarcodeService;

    /**
     * 查询条码管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:barcode:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmesBarcode smesBarcode)
    {
        startPage();
        List<SmesBarcode> list = smesBarcodeService.selectSmesBarcodeList(smesBarcode);
        return getDataTable(list);
    }

    /**
     * 导出条码管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:barcode:export')")
    @Log(title = "条码管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmesBarcode smesBarcode)
    {
        List<SmesBarcode> list = smesBarcodeService.selectSmesBarcodeList(smesBarcode);
        ExcelUtil<SmesBarcode> util = new ExcelUtil<SmesBarcode>(SmesBarcode.class);
        return util.exportExcel(list, "barcode");
    }

    /**
     * 获取条码管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('systembasic:barcode:query')")
    @GetMapping(value = "/{barcodeData}")
    public AjaxResult getInfo(@PathVariable("barcodeData") String barcodeData)
    {
        return AjaxResult.success(smesBarcodeService.selectSmesBarcodeById(barcodeData));
    }

    /**
     * 新增条码管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:barcode:add')")
    @Log(title = "条码管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmesBarcode smesBarcode)
    {
        return toAjax(smesBarcodeService.insertSmesBarcode(smesBarcode));
    }

    /**
     * 修改条码管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:barcode:edit')")
    @Log(title = "条码管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmesBarcode smesBarcode)
    {
        return toAjax(smesBarcodeService.updateSmesBarcode(smesBarcode));
    }

    /**
     * 删除条码管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:barcode:remove')")
    @Log(title = "条码管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{barcodeDatas}")
    public AjaxResult remove(@PathVariable String[] barcodeDatas)
    {
        return toAjax(smesBarcodeService.deleteSmesBarcodeByIds(barcodeDatas));
    }
}